// const { delFindNode } = require("../utils/dom");
const isDev = process.env.NODE_ENV === "development";
module.exports = {
  indexName: "README.md", //首页md文件的名称
  excludes: [isDev ? "" : "demo"], //.vuepress构建页面时，需要排除的文件夹或文件名
  crawlerMap: {
    /**
     * 爬取 git 教程网站内容
     * @link 官网地址： https://git-scm.com/book/zh/v2
     */
    git: {
      title: "Git教程", //标题，用作顶部导航栏、home页features的标题显示
      basePath: "https://git-scm.com", //网站基础路径
      /**
       * 对象或者数组，
       * @param 如为对象：{url: "/book/zh/v2", selectors: [".book-toc h2", "+ol"]}
       * @param 如为数组：[{id: '1', href: '', title: '', children: []}]
       */
      navs: {
        url: "/book/zh/v2", //获取导航数据的html网页地址路径
        selectors: [".book-toc h2", "+ol"], //一级、二级…… 或多级目录的选择器
      },
      //处理模板，可使用字符串，目前内置有：runoob, juejin
      handleTpl: {
        selector: "#main", //默认body。子页面的内容区域的选择器元素
        //对刚读取到的完整html文件进行处理
        handleOriginHtmlFile(htmlFile, fileName) {
          //6.3.html 有处代码有问题，故需要处理，否则会在当md文件生成网页时报错，导致页面展示不出来
          if (fileName === "6.3") {
            htmlFile = htmlFile.replace(/&amp;gt/g, "&gt;");
          }
          return htmlFile;
        },
        //对html文件中指定的内容主体的html文本进行处理
        handleMainHtmlFile(html, fileName) {
          html = html
            .replace(/<h5/g, `<h6`)
            .replace(/\/h5>/g, `\/h6>`)
            .replace(/<h4/g, `<h5`)
            .replace(/\/h4>/g, `\/h5>`)
            .replace(/<h3/g, `<h4`)
            .replace(/\/h3>/g, `\/h4>`)
            .replace(/<h2/g, `<h3`)
            .replace(/\/h2>/g, `\/h3>`)
            .replace(/<h1/g, `<h2`)
            .replace(/\/h1>/g, `\/h2>`);
          // return delFindNode(html, "#nav");
          return html;
        },
      },
    },
    /**
     * 爬取 Markdown 官网网站内容
     * @link 官网地址： http://markdown.p2hp.com/index.html
     */
    markdown: {
      title: "Markdown教程",
      basePath: "http://markdown.p2hp.com",
      navs: [
        {
          id: "1",
          title: "入门",
          href: "/getting-started/",
        },
        { id: "2", title: "基本语法", href: "/basic-syntax/" },
        { id: "3", title: "扩展语法", href: "/extended-syntax/" },
        { id: "4", title: "备忘表", href: "/cheat-sheet/" },
      ],
      handleTpl: {
        selector: ".container .row", //默认body
      },
    },
    /**
     * 爬取 regexp 正则表达式
     * @link 官网地址：
     */
    regexp: {
      title: "regexp教程",
      basePath: "https://www.runoob.com",
      navs: [
        {
          id: "1",
          title: "表达式全集",
          href: "https://tool.oschina.net/uploads/apidocs/jquery/regexp.html",
        },
      ],
      handleTpl: {
        selector: "body", //默认body
      },
    },
    /**
     * 爬取 jquery 菜鸟教程网站内容
     * @link 官网地址： https://www.runoob.com/jquery/jquery-tutorial.html
     */
    jquery: {
      title: "Jquery教程",
      basePath: "https://www.runoob.com",
      home: {
        // id: "0",
        // title: "基础",
        // href: "/jquery/jquery-intro.html",
        children: [
          {
            id: "0.1",
            title: "简介",
            href: "/jquery/jquery-intro.html",
          },
          {
            id: "0.2",
            title: "安装",
            href: "/jquery/jquery-install.html",
          },
          {
            id: "0.3",
            title: "语法",
            href: "/jquery/jquery-syntax.html",
          },
          {
            id: "0.4",
            title: "选择器",
            href: "/jquery/jquery-selectors.html",
          },
          {
            id: "0.5",
            title: "事件",
            href: "/jquery/jquery-events.html",
          },
        ],
      },
      navs: {
        url: "/jquery/jquery-tutorial.html", //获取导航数据的html网页地址路径
        selectors: ["#leftcolumn h2", "-h2"],
      },
      handleTpl: "runoob",
    },
    /**
     * 爬取掘金 ts 网站内容
     * @link
     */
    ts: {
      title: "TypeScript基础",
      basePath: "https://juejin.cn/post",
      navs: [
        {
          id: "1",
          title: "第一部分",
          href: "/7102384712504573982",
        },
        { id: "2", title: "第二部分", href: "/7102996554541170696" },
      ],
      handleTpl: "juejin",
    },
    /**
     * 爬取 掘金 网页内容
     * @link 官网地址： https://juejin.cn/
     */
    note: {
      title: "杂记",
      basePath: "https://juejin.cn/post",
      navs: [
        {
          id: "1",
          title: "vue2源码解读",
          href: "/6949370458793836580",
          children: [
            { id: "1.1", title: "前言", href: "/6949370458793836580" },
            { id: "1.2", title: "前言", href: "/6950084496515399717" },
            { id: "1.3", title: "前言", href: "/6950826293923414047" },
          ],
        },
        {
          id: "2",
          title: "vue3源码解读",
          href: "/6949370458793836580",
          children: [
            {
              id: "2.1",
              title: "createApp",
              href: "/6881910894473773069",
            },
            {
              id: "2.2",
              title: "mount",
              href: "/6883072260123394061",
            },
            {
              id: "2.3",
              title: "patch",
              href: "/6883398472368652296",
            },
            {
              id: "2.4",
              title: "compositionApi",
              href: "/6893045604592418830",
            },
          ],
        },
        {
          id: "3",
          title: "设计模式",
          href: "/7072175210874535967",
        },
        {
          id: "4",
          title: "ES6特性概括", //(至ES2020)
          href: "/6844903959283367950",
        },
        {
          id: "5",
          title: "正则表达式",
          href: "/7101213997487095844",
        },
      ],
      handleTpl: "juejin",
    },
    /**
     * 前端面试题： 爬取 掘金 网页内容
     * @link 官网地址： https://juejin.cn/
     */
    interview: {
      title: "面试题",
      basePath: "https://juejin.cn/post",
      navs: [
        {
          id: "1",
          title: "Html",
          href: "/7095899257072254989",
        },
        {
          id: "2",
          title: "CSS",
          href: "/7098689890933538853",
        },
        {
          id: "3",
          title: "JavaScript",
          href: "/7197070078360322109",
          children: [
            {
              id: "3.1",
              title: "第一部分",
              href: "/7153593226526457887",
            },
            {
              id: "3.2",
              title: "第二部分",
              href: "/7155647370233905188",
            },
            {
              id: "3.3",
              title: "第三部分",
              href: "/7159042278252609550",
            },
          ],
        },
        {
          id: "4",
          title: "网络",
          href: "/7197070078360322109",
        },
        {
          id: "5",
          title: "前端面试题-偏难",
          href: "/6844903821429178382",
        },
      ],
      handleTpl: "juejin",
    },
  },
};
